package com.yc;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @author zwei
 * @create 2024-07-18 15:54
 */
public class Test3_Client {
    public static void main(String[] args) throws IOException {
        //编写客户端 连接服务  192.168.16.222
//        Socket s=new Socket("60.205.91.68",10001);   //阿里云的
        Socket s=new Socket("localhost",10001);   //本地的
        System.out.println("连接成功，"+s);
        //用输入流来接时间
        try (InputStreamReader iis=new InputStreamReader( s.getInputStream() ) ){
            char[]chs=new char[1024];
            int length=-1;
            System.out.println("客户端等待服务端的响应");
            while ((length=iis.read(chs,0,chs.length))!=-1){
                String str=new String(chs,0,length);
                System.out.println("服务端的响应："+str);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        System.out.println("客户端断开与服务器的连接");
        s.close();
    }
}
